﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;

namespace ExpiredTools
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;
            DataTable dt = new DataTable();
            using (SqlConnection con = new SqlConnection(@"Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=CS6;Data Source=.\SQL08r2"))
            {
                using (var cmd = con.CreateCommand())
                {
                    cmd.CommandText = "SELECT DISTINCT FILENAME FROM [PATIENTIMAGEDATATABLE] s";
                    SqlDataAdapter sda = new SqlDataAdapter(cmd);
                    sda.Fill(dt);
                }
            }
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow dr = dt.Rows[i];
                string FILENAME = dr["FILENAME"].ToString();
                FILENAME = FILENAME.Replace(@"\\NEOHEATH", @"G:\NEOHEATH");
                DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(FILENAME));
                if(!dir.Exists)
                {
                    dir.Create();
                }
                if (File.Exists(FILENAME))
                    continue;
                File.AppendAllText(FILENAME, "FILENAME", Encoding.UTF8);
            }

            using (SqlConnection con = new SqlConnection(@"Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=CS6;Data Source=.\SQL08r2"))
            {
                using (var cmd = con.CreateCommand())
                {
                    cmd.CommandText = "SELECT DISTINCT FILENAME FROM [GRAPHICTEMPLATETABLE] s";
                    SqlDataAdapter sda = new SqlDataAdapter(cmd);
                    sda.Fill(dt);
                }
            }
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow dr = dt.Rows[i];
                string FILENAME = dr["FILENAME"].ToString();
                FILENAME = FILENAME.Replace(@"\\NEOHEATH", @"G:\NEOHEATH");
                DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(FILENAME));
                if(!dir.Exists)
                {
                    dir.Create();
                }
                if (File.Exists(FILENAME))
                    continue;
                File.AppendAllText(FILENAME, "FILENAME", Encoding.UTF8);
            }
            button1.Enabled = true ;
            MessageBox.Show("Done");
        }
    }
}
